<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/3/25
  Time: 15:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% request.setCharacterEncoding("UTF-8") ;%>
<html>
<head>
    <title>修改信息</title>
    <meta http-equiv="refresh" content="2;URL=/userList.jsp">

</head>
<body>
<%
    //JDBC 3+1
    Connection connection = null;
//    Statement statement = null;
//    ResultSet resultSet = null;

    String sql = "UPDATE t_users SET name =?,password=? WHERE id=?";

    Class.forName("com.mysql.jdbc.Driver");

    connection = DriverManager.getConnection(
            "jdbc:mysql://localhost:3306/sctu_javaweb_2018?characterEncoding=utf-8&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC",
            "root",
            "123456"
    );

    //预编译
    PreparedStatement preparedStatement = connection.prepareStatement(sql); //预编译SQL，减少sql执行


    //传参
    preparedStatement.setString(1, request.getParameter("name"));
    preparedStatement.setString(2, request.getParameter("password"));
    preparedStatement.setString(3, request.getParameter("id"));

    //执行
    preparedStatement.execute();


    connection.close();
    preparedStatement.close();

    // 重定向到新地址
    String site = new String("/userList.jsp");
    response.setStatus(response.SC_MOVED_TEMPORARILY);
    response.setHeader("Location", site);
%>

</body>
</html>
